This tutorial presents another example of solving ordinary differential equations using odeint().

The differential equation that we will attempt to solve is:

$\ddot{z}=-\dfrac{1}{z}\left(\dot{z}^2+b\dot{z}+gz-gh\right)$.

In this expression, $z$ the height of water inside a straw with one end partially submerged in a cup of water. Oscillations of the water level are induced by an initial pressure difference between the inside of the straw and the surface of the water in the cup (at one atmosphere). For more details, see R. P. Smith and E. H. Matlis, American Journal of Physics 87, 433 (2019).

$g = 9.81~\mathrm{m}/\mathrm{s}^2$
$h$ is the depth that the straw is submerged in the water
$b$ is a drag coefficient

The strategy to solve a second-order differential equation using odeint() is to write the equation as a system of two first-order equations. This is achieved by first writing $x[1] = \dot{z}$ and $x[0] = z$. In that case, or original second-order equation can be expressed as:

$\ddot{z}=\dot{x}[1]=-\dfrac{1}{x[0]}\left(x[1]^2+bx[1]+gx[0]-gh\right)$.

One of our first-order equations is the expression above and the other is simply $\dot{z}=x[1]$.